<template>
	<view>
		<view class="plr15 ptb20">
			<view class="bgWhite box radius10">
				<view class="bdbe plr15">
					<view class="gray9 ft12 ptb12">{{$t('mine').提现金额}}</view>
					<view class="align-center inputbox">
						<!-- {{selcurrency=='USD'?'$':'￥'}} -->
						<view class="">￥</view>
						<input v-model="inputMoney" type="digit" style="font-size: 48rpx;" class="flex1 plr10"
							placeholder-class="placeholder" :placeholder="$t('mine').请输入提现金额" @input="floatInput" />
						<view class="bglight radius22 white btn tc ft14" @click="allMoney()">{{$t('mine').全部提现}}</view>
					</view>
				</view>
				<view class="gray9 ft12 ptb12 plr15">
					<!-- {{$t('index').元}} -->
					<!-- {{selcurrency=='USD'?$t('index').美元 : $t('index').元}} -->
					{{$t('mine').可提现金额}}：{{userInfo.view_money}}
				</view>
			</view>
			<view v-if="selcurrency==1 &&confirmid==0"><mix-button ref="confirmBtn" text="下一步" marginTop="70rpx"
					@onConfirm="navTo('/pages/wallet/editoverseas')"></mix-button></view>
			<view v-else>
				<mix-button ref="confirmBtn" :text="$t('common').确认" marginTop="70rpx" @onConfirm="submit" :disabled="disabled"></mix-button>
				<mix-button ref="confirmBtn" :text="$t('mine').上传推广凭证" marginTop="36rpx" @onConfirm="navTo('upimg')"
					style="background: none;color: #F44A42;border: 1px solid #F4564E;" v-if="userInfo.area == 1"></mix-button>
			</view>
			<view class="ptb30 gray6 bdbe">

				<view><text>{{$t('mine').提现说明}}：</text></view>
				<view v-if="userInfo.area == 1">
					<view><text>{{$t('mine').该笔款项将提现到你尾号}}{{bank_num.slice(-4)}}{{$t('mine').的银行卡}}</text></view>
					<!-- <view v-else><text>{{$t('mine').请绑定银行卡}}</text></view> -->
					<view><text>{{$t('mine').提现将收7取综合服务费}}</text></view>
					<view><text>{{$t('mine').提现前请先完成上传推广凭证}}</text></view>
					<view><text>4.{{$t('mine').提现日仅支持发起1次提现}}</text></view>
				</view>
				<view v-else>
					<!-- v-if="this.userInfo.sign_status" -->
					<view><text>{{$t('mine').该笔款项将提现到你尾号}}{{bank_num.slice(-4)}}{{$t('mine').的银行卡}}</text></view>
					<!-- <view v-else><text>{{$t('mine').请绑定银行卡}}</text></view> -->
					<view><text>{{$t('mine').提现将收7取综合服务费}}</text></view>
					<view><text>3.{{$t('mine').提现日仅支持发起1次提现}}</text></view>

				</view>
			</view>
			<view class="h45 align-center bdbe justify-between ft15" @click="navTo('log')">
				<text>{{$t('mine').提现记录}}</text>
				<uni-icons type="arrowright" style="color: #bbbbbb!important;"></uni-icons>
			</view>
			<view v-if="(userInfo.sign_status==2&&userInfo.area==1)" class="h45 align-center bdbe justify-between ft15"
				@click="navTo('bindCard?'+(userInfo.area==2?'val=1':''))">
				<text>{{$t('mine').换绑银行卡}}</text>
				<uni-icons type="arrowright" style="color: #bbbbbb!important;"></uni-icons>
			</view>
			<view v-else-if="(userInfo.area==2)" class="h45 align-center bdbe justify-between ft15"
				@click="navTo('/pages/wallet/perfect-rebinding')">
				<text>{{$t('mine').换绑银行卡}}</text>
				<uni-icons type="arrowright" style="color: #bbbbbb!important;"></uni-icons>
			</view>
		</view>
		<u-modal :disabled="disabled" title="" :show="show" :confirmText="$t('common').确认" :cancelText="$t('common').取消" showCancelButton
			confirmColor="#F44A42" closeOnClickOverlay @confirm="confirm" @cancel="close">
			<view class="" style="width: 600rpx;">
				<!--  {{selcurrency=='USD'?$t('index').美元 : $t('index').元}}-->
				<view class="ft16">{{$t('mine').你正在发起}}{{inputMoney}}{{$t('index').元}}{{$t('mine').的提现申请}}
				</view>
				<view class="mt10">
					<text>{{$t('mine').综合服务费}}：</text>
					<text class="light">{{fee}}{{selcurrency=='USD'?$t('index').美元 : $t('index').元}}</text>
				</view>
				<view class="mt10">
					<text>{{$t('mine').实际到账}}：</text>
					<!-- {{selcurrency=='USD'?$t('index').美元 : $t('index').元}} -->
					<text class="light">{{realityMoney}}{{$t('index').元}}</text>
				</view>
			</view>
		</u-modal>
		<u-modal title="" :content="$t('mine').正在进行个体商户认证流程请点击继续认证前往操作" :show="show2" showCancelButton
			confirmColor="#F44A42" closeOnClickOverlay :cancelText="$t('fan').我知道了" :confirmText="$t('mine').继续认证"
			@confirm="confirm2" @cancel="close2">
		</u-modal>

		<!-- 实名认证弹窗 -->
		<u-overlay :show="is_show1" opacity=".4">
			<view class="t-box">
				<view class="txt3" style="" @tap.stop>
					<view class="title1">提现前请先完成“身份证”信息上传</view>
					<view class="bot-btn1">
						<view class="btn-l" @click="ref1()">{{$t('mine').暂不提现}}</view>
						<view class="line1"></view>
						<view class="btn-r" @click="agree1()">{{$t('mine').立即上传}}</view>
					</view>

				</view>
			</view>
		</u-overlay>

	</view>
</template>
<script>
	export default {
		data() {
			return {
				disabled:false,//禁用提现按钮
				is_show1: false,//实名认证弹窗
				show: false,
				show2: false,
				confirmid: 1,
				money: '', //全部可提现金额
				inputMoney: '', //输入的提现金额
				fee: '', //服务费
				realityMoney: '', //实际到账
				selcurrency: uni.getStorageSync('currency'), //是否为海外版
				rate: uni.getStorageSync('rate'), //是否为海外版
				sign_status: '', //是否需要个体户认证
				minMoney: 20,
				cert_type: '', //身份
				bank_num: '', //银行卡号
				disabled:false
			}
		},
		onLoad(options) {
			if(options.val&&options.val==1){
				//国外
				this.is_show1 = false
			}
			// this.money = options.money
			if (this.userInfo.area == 1) {
				this.minMoney = 20
			} else{
				this.minMoney = this.userInfo.gat_min_tx_money
			}
			if (this.selcurrency == 'USD') {
				this.minMoney = 20 * this.rate
			}
			uni.setNavigationBarTitle({
				title: this.$t('mine').提现
			})
		},
		onShow() {
			this.$store.dispatch('getuserInfo')
			this.getbankAPI()
		},
		computed: {
			userInfo() {
				return this.$store.state.userInfo
			},
			lang() {
				return this.$store.state.lang
			}
		},
		methods: {
			ref1(){
				this.navTo('/pages/wallet/index')
				this.is_show1=false
			},
			agree1(){
				this.navTo('/pages/wallet/realname')
				this.is_show1=false
			},
			//处理两位小数
			floatInput(val) {
				this.$utils.debounce(() => {
					let checkPlan = "" + val.detail.value;
					checkPlan = checkPlan
						.replace(/[^\d.]/g, "") // 清除“数字”和“.”以外的字符
						.replace(/\.{2,}/g, ".") // 只保留第一个. 清除多余的
						.replace(/^\./g, "") // 保证第一个为数字而不是.
						.replace(".", "$#$")
						.replace(/\./g, "")
						.replace("$#$", ".");
					if (checkPlan.indexOf(".") < 0 && checkPlan !== "") {
						// 以上已经过滤，此处控制的是如果没有小数点，首位不能为类似于 01、02的金额
						checkPlan = parseFloat(checkPlan) + "";
					} else if (checkPlan.indexOf(".") >= 0) {
						checkPlan = checkPlan.replace(/^()*(\d+)\.(\d\d).*$/, "$1$2.$3"); // 只能输入两个小数
					}

					this.$nextTick(() => (this.inputMoney = checkPlan ? checkPlan * 1 : ''));
					return checkPlan;
				}, 200)
			},
			async submit() {
				if (this.inputMoney === '') {
					return this.$utils.msg(this.$t('mine').请输入提现的金额)
				}
				if (this.inputMoney < this.minMoney) {
					// (this.selcurrency == 'USD' ? this.$t('index').美元 : this.$t('index').元))
					return this.$utils.msg(this.$t('mine').最低提现 + this.minMoney + this.$t('index').元)
				}
				if (this.inputMoney > Number(this.userInfo.view_money)) {
					// this.$utils.msg(this.$t('mine').最多可提现 + this.userInfo.view_money + this.$t('index').元 + (
					// this.lang == 'en' ? ',' : '，') + this.userInfo.view_money + this.$t('mine').为可提现金额)
					return this.$utils.msg(this.$t('mine').超过最大可提现金额)
				}
				const res = await this.$api.countwithdraw({
					money: this.inputMoney
				})
				if (res && res.code == 1) {
					this.fee = res.data.fee
					this.realityMoney = res.data.money
					this.show = true;
					this.sign_status = res.data.sign_status
					this.cert_type = res.data.cert_type
				}

			},
			open() {

			},
			close() {
				this.show = false
			},
			docuconfirm() {
				this.disabled = false
				this.$utils.debounce(() => {
					this.confirm()
				}, 500)
			},
			async confirm() {
				this.disabled = true
				if (this.cert_type == 2 && this.sign_status != 2) {
					// 需要个体会认证
					this.show = false
					this.show2 = true
				} else {
					this.show = false
					// this.show2 = true
					const res = await this.$api.applywithdraw({
						money: this.inputMoney
					})
					if (res && res.code == 1) {
						this.$utils.msg(this.$t('mine').提现成功)
						setTimeout(() => {
							uni.navigateTo({
								url: '/pages/wallet/index'
							})
						}, 300)
					}
				}

				// if (res && res.code == -1) {
				// 	// 判断是否电签
				// 	uni.showModal({
				// 		content: '请绑定银行卡',
				// 		confirmColor: "#F44A42",
				// 		success: function(res) {
				// 			if (res.confirm) {
				// 				uni.navigateTo({
				// 					url: '/pages/wallet/bindCard?isbind=-1'
				// 				})
				// 			}
				// 		}
				// 	})
				// } else {
				// 	// 判断电签过是否需要企业电签
				// 	if (500 < this.limit) {
				// 		this.show2 = true
				// 	}
				// }
			},
			close2() {
				this.show2 = false
			},
			async confirm2() {
				this.show2 = false
				// this.navTo(`/pages/wallet/bindCard?sign_status=${this.sign_status}`)
				const res = await this.$api.getContractUrl({
					cert_type: 2
				})
				if (res && res.code == 1) {
					// location.href = 'https://' + res.data.url
					location.href = res.data.url
				}
			},
			// 全部提现
			allMoney() {
				this.inputMoney = this.userInfo.view_money
			},
			// 获取回显的银行卡信息
			async getbankAPI() {
				const res = await this.$api.getbank()
				if (res && res.code == 1) {
					if (this.userInfo.area == 1) {
						//国内
						if (this.userInfo.sign_status == 1) {
							this.navTo(`/pages/wallet/bindCard`) //电签（国内、港澳）、国内换绑银行卡
							// this.navTo('/pages/wallet/perfect-rebinding')//港澳完善、换绑
							// this.navTo('/pages/wallet/progress')//港澳电签进度
							// this.navTo('/pages/wallet/agency')//港澳在线签约
							// this.navTo(`/pages/wallet/withdraw`)//提现 
					
						}
						if (res.data.front_img) {
							this.is_show1 = false
						}
						else{
							this.is_show1 = true
						}
					} else {
						if (res.data && res.data.username) {
							if (res.data.step && res.data.step == 3) {
							} else if (res.data.step && res.data.step >= -1) {
								this.navTo('/pages/wallet/progress?val=' + res.data.step)
							}else{
								this.navTo(`/pages/wallet/bindCard?val=1`)
							}
											
						} else {
							this.navTo(`/pages/wallet/bindCard?val=1`)
						}
						//港澳台提现
						//判断当前币种
						// this.is_show1=true
						// if (this.userInfo.sign_status == 1) {
						// 	this.navTo(`/pages/wallet/withdraw?val=1`)//提现 
						// } else {
						// 	this.navTo(`/pages/wallet/bindCard?val=1`)//电签（国内、港澳）、国内换绑银行卡
						// }
					
					}
					this.bank_num = res.data.bank_num
				}
			}

		}
	}
</script>

<style lang="scss">
	page {
		background-color: #ffffff;
	}

	.box {
		box-shadow: 0px 0px 36px 4px rgba(198, 201, 205, 0.2);
		background: url('../../static/images/wallet/walletbg.png') no-repeat;
		background-size: cover;

		.inputbox {
			font-size: 54upx;
			padding-bottom: 15upx;

			.placeholder {
				font-size: 48upx;
				color: #BBBBBB;
			}
		}

		.btn {
			width: 164upx;
			height: 56upx;
			line-height: 56upx;
		}
	}
	
	.t-box {
		height: 100vh;
		width: 100vw;
		display: flex;
		justify-content: center;
		align-items: center;
	
		.txt3 {
			width: 640upx;
			height: 278upx;
			background: #FFFFFF;
			margin-top: -260upx;
			border-radius: 10upx;
			
			.title1{
				text-align: center;
				margin-top: 84upx;
				font-size: 32upx;
			}
			.bot-btn1{
				border-top: 1upx solid #EEEEEE;
				margin-top: 56upx;
				width: 640upx;
				height: 96upx;
				display: flex;
				justify-content: space-between;
				text-align: center;
				align-items: center;
				font-size: 30upx;
				.btn-l{
					width: 319upx;
					color: #333333;
				}
				.line1{
					width: 2upx;
					height: 94upx;
					background-color: #EEEEEE;
				}
				.btn-r{
					width: 319upx;
					color: #F44A42;
				}
			}
	
		}
	
	}
</style>